package com.hpjz.basicofing.web.controller;


import java.util.List;

import javax.annotation.Resource;

import lombok.extern.log4j.Log4j;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hpjz.basicofing.service.IOrganizationService;
import com.hpjz.basicofing.web.vo.OrganizationVO;
import com.hpjz.common.ParameterBean;
import com.hpjz.common.ResultBean;
import com.hpjz.common.utils.ConstantDefinition;

@Controller
@RequestMapping("/organization")
@Log4j
public class OrganizationController {
	
	/**
	 * 机构service
	 */
	@Resource
	private IOrganizationService organizationService;
	
	
	/**
	 * 添加组织机构
	 * @param pb
	 * @return
	 */
	@RequestMapping(value="/insertOrg",method = RequestMethod.POST)
	public @ResponseBody ResultBean insertOrganization(@RequestBody ParameterBean pb){
		OrganizationVO objMap = (OrganizationVO) pb.getParameter(OrganizationVO.class);
		ResultBean result = new ResultBean();
		 try {
			 
			 this.organizationService.insertOrganization(objMap);
			 result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
		} catch (Exception e) {
			 log.error("添加机构信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}

	/**
	 * 查询组织机构信息
	 * @param pb
	 * @return
	 */
	@RequestMapping(value="/findOrganization",method = RequestMethod.POST)
	public @ResponseBody ResultBean findOrg(@RequestBody ParameterBean pb){
		OrganizationVO objMap = (OrganizationVO) pb.getParameter(OrganizationVO.class);
		ResultBean result = new ResultBean();
		 try {
			 OrganizationVO uvo =  this.organizationService.findOrganization(objMap);
			 result.setResult(uvo);
			 result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
		} catch (Exception e) {
			 log.error("查询机构信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}
	
	/**
	 * 修改组织机构信息
	 * @param pb
	 * @return
	 */
	@RequestMapping(value="/updateOrganization",method = RequestMethod.POST)
	public @ResponseBody ResultBean updateOrg(@RequestBody ParameterBean pb){
		OrganizationVO objMap = (OrganizationVO) pb.getParameter(OrganizationVO.class);
		ResultBean result = new ResultBean();
		 try {
			  this.organizationService.updateOrganization(objMap);
			  result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
			 
		} catch (Exception e) {
			 log.error("查询机构信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}
	
	
	
	 /**
	  * 删除组织机构信息
	  * @param pb
	  * @return
	  */
	@RequestMapping(value="/deleteOrganization",method = RequestMethod.POST)
	public @ResponseBody ResultBean deleteOrg(@RequestBody ParameterBean pb){
		OrganizationVO objMap = (OrganizationVO) pb.getParameter(OrganizationVO.class);
		ResultBean result = new ResultBean();
		 try {
			 this.organizationService.deleteOrganization(objMap);
			 result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
		} catch (Exception e) {
			 log.error("删除机构信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}
	
	/**
	 * 查询所有组织机构信息
	 * @param pb
	 * @return
	 */
	@RequestMapping(value="/findAllOrgs",method = RequestMethod.POST)
	public @ResponseBody ResultBean findAllOrgs(@RequestBody ParameterBean pb){
		/*OrganizationVO objMap = (OrganizationVO) pb.getParameter(OrganizationVO.class);*/
		ResultBean result = new ResultBean();
		 try {
			 List<OrganizationVO>  orgs = this.organizationService.findAllOrgs();
			 result.setResult(orgs);
			 result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
		} catch (Exception e) {
			 log.error("查询所有组织结构信息失败！",e);
			 result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		 return result;
	}
	
}
